<?php
class Vfriend_Cache_Delete
{
	public $server = null;

	public function __construct($server)
	{
		$this->server = $server;
	}	

	public function delete($key)
	{		
		$r = $this->server->delete($key);
		return $r;
	}

	public function addPrefix($strKey, $strId)
	{
		$arrId = explode(',', $strId);
		for($i = 0; $i < count($arrId); $i++) {
			$arrId[$i] = $strKey . $arrId[$i];
		}
		return $arrId;
	}
	/** USER */
	public function deleteUser($intUserId) {
		$this->delete(USER_GET . $intUserId);
		$this->delete(USER_GET_ADDINFO . $intUserId);
		$this->delete(USER_GET_FULL . $intUserId);
		$this->delete(USER_GET_PREFERENCE . $intUserId);
		$this->delete(USER_GET_RELATION . $intUserId);
		$this->deleteBlog($intUserId);
	}	
	public function deleteUserByEmail($strEmail) {
		$this->delete(USER_GET_INFOBYEMAIL . $strEmail);
		$this->delete(USER_GET_PASSWORD . $strEmail);
		$this->delete(USER_GET_FULLEMAIL . $strEmail);
	}
	public function deleteUserByHexUserId($intHexUserId) {
		$this->delete(USER_GET_INFOBYHEXUSERID . $intHexUserId);
	}
	public function deleteUserByUsername($strUsername) {
		$this->delete(USER_GET_INFOBYUSERNAME . $strUsername);
	}
	public function deleteUserNotification($intUserId) {
		$this->delete(USER_GET_USERNOTIFICATION . $intUserId);
	}	
	public function deletePhotoGet($intUserId, $intImageId) {
		$this->deleteUser($intUserId);
		$this->delete(PHOTO_GET . $intUserId . $intImageId);
	}
	public function deleteAccount($intUserId, $intType=1) {
		$this->delete(USER_GET_ACCOUNT . $intUserId . $intType);
	}
	public function deleteUpreference($intUserId) {
		$this->delete(USER_GET_UPREFERENCE . $intUserId . QUESTION_ID_OTHER);
		$this->delete(USER_GET_UPREFERENCE . $intUserId . QUESTION_ID_MOVIE);
		$this->delete(USER_GET_UPREFERENCE . $intUserId . QUESTION_ID_MUSIC);
		$this->delete(USER_GET_UPREFERENCE . $intUserId . QUESTION_ID_SPORT);
		$this->delete(USER_GET_PREFERENCE . $intUserId);
	}
	public function deleteUstat($intUserId) {
		$this->delete(USER_GET_USERSTAT . $intUserId);
	}
	public function deleteLike($intUserId, $intTargetId) {
		$this->delete(USER_CHECK_LIKE . $intUserId . $intTargetId);
	}
	/** CONTENT */
	public function deleteContentByPage($strAction) {
		$this->delete(CONTENT_GETBYPAGE . $strAction);
	}
	/** COMMON */
	public function deleteCommonSeo($strController, $strAction) {
		$this->delete(COMMON_GETSEO . $strController . $strAction);
	}
	public function deleteCommonByUserId($intUserId) {
		$this->delete(COMMON_GETEDUCATION . $intUserId);
		$this->delete(COMMON_GETOCCUPATION . $intUserId);
		$this->delete(COMMON_GETPOSITION . $intUserId);
		$this->delete(COMMON_GETMARITAL . $intUserId);
		$this->delete(COMMON_GETRELIGION . $intUserId);
		$this->delete(COMMON_GETPREFERENCE . $intUserId);
	}
	public function deleteAdminById($intAdminId) {
		$this->delete(BACKEND_ADMIN_GETPERMISSIONBYADMIN . $intAdminId);
		$this->delete(BACKEND_ADMIN_GET . $intAdminId);
	}
	public function deleteAdminByUsername($strUsername) {
		$this->delete(BACKEND_ADMIN_GETINFOBYUSERNAME . $strUsername);
	}
	public function deleteAdPermission($intAdminId, $intSectionId) {
		$this->delete(BACKEND_ADMIN_GETPERMISSION . $intAdminId . $intSectionId);
	}
	/** BLOG */
	public function deleteBlogById($intBlogId) {
		$this->delete(BLOG_GET . $intBlogId);
		$this->delete(BACKEND_BLOG_GET . $intBlogId);
		$this->delete(BLOG_GETCMTUSER . $intBlogId);
		$this->delete(BLOG_GETCMTTOTAL . $intBlogId);
		$this->delete(BLOG_GETTOPCMT . $intBlogId);
		$this->delete(BLOG_GETLIKE . $intBlogId);
		$this->delete(BLOG_GETQUOTE . $intBlogId . '12');
		$this->delete(BLOG_GETQUOTE . $intBlogId . '14');
	}
	public function deleteBlog($intUserId=0) {
		$this->delete(BLOG_GETALL . 1);		
		$this->delete(BLOG_GETALL . 3);
		$this->delete(BLOG_GETALL . 4);
		$this->delete(BLOG_GETALL . 5);
		if($intUserId > 0) {
			$this->delete(BLOG_GETALL . '2' . $intUserId);
			$this->delete(BLOG_GETALL . '5' . $intUserId);
		} else {
			$this->delete(BLOG_GETALL . '20');
			$this->delete(BLOG_GETALL . '50');
		}
		$this->delete(BLOG_GETALLBYUSER . $intUserId);
		$this->deleteUstat($intUserId);
	}
	/** CATEGORY */
	public function deleteCategoryById($intCategoryId) {
		$this->delete(COMMON_GETCATEGORYBYID . $intCategoryId);
		$this->delete(BACKEND_CATEGORY_GET . $intCategoryId);
	}
	public function deleteCategoryByType($intParentId, $intType) {
		$this->delete(COMMON_GETCATEGORY . $intParentId . $intType . 0);
		$this->delete(COMMON_GETCATEGORY . $intParentId . $intType . 1);
	}
	/** PRODUCT */
	public function deleteProductId($intProductId) {
		$this->delete(BACKEND_PRODUCT_GET . $intProductId);
		$this->delete(PRODUCT_GET . $intProductId);
		$this->delete(PRODUCT_GETNAME . $intProductId);
	}
	public function deleteProductByUser($intUserId, $intProductId) {
		$this->delete(PRODUCT_GETALLFORGIFT . $intUserId);
		$this->delete(PRODUCT_GETALLFORFORTUNE . $intUserId);
		$this->delete(PRODUCT_GETALLFORPRODUCT . $intUserId . $intProductId);
	}
	public function deleteBasket($intUserId, $intTargetId=0) {
		$this->delete(PRODUCT_GETALLFORPROPOSE . $intUserId);
		$this->delete(PRODUCT_GETBASKET . $intUserId . $intTargetId);
		$this->delete(PRODUCT_GETBASKETSTA . $intUserId . $intTargetId);
		$objVfriendUser	= new Vfriend_User();
		$intPartnerId 	= $objVfriendUser->getPartner($intUserId);
		if($intPartnerId > 0) {
			$this->delete(PRODUCT_GETALLFORPROPOSE . $intPartnerId);
			$this->delete(PRODUCT_GETBASKET . $intPartnerId . $intTargetId);
			$this->delete(PRODUCT_GETBASKETSTA . $intPartnerId . $intTargetId);
		}
		if($intTargetId > 0) {
			$this->delete(PRODUCT_GETALLFORGIFT . $intTargetId);
			$this->delete(PRODUCT_GETALLFORPROPOSE . $intTargetId);					
		}
	}
	/** REQUEST */
	public function deleteRequest($intUserId) {
		$this->delete(REQUEST_GETALL . $intUserId);
		$this->delete(REQUEST_GETUNREAD . $intUserId);
	}
	public function deleteBlacklist($intUserId) {
		$this->delete(REQUEST_GETALLFORBLACKLIST . $intUserId);
	}
	/** RELATION */
	public function deleteRelation($intUserId,$intTargetId=0) {
		$this->delete(USER_GET_RELATION . $intUserId);
		$this->delete(USER_GET_PARTNER . $intUserId . '0');
		$this->delete(USER_GET_PARTNER . $intUserId . '1');
		$this->delete(USER_GET_FULLHOUSE . $intUserId);
		if($intTargetId > 0) {
			$this->delete(USER_GET_RELATIONTYPE . $intUserId . $intTargetId);
			$this->delete(USER_GET_RELATIONTYPE . $intTargetId . $intUserId);
			$this->delete(USER_GET_FULLHOUSE . $intTargetId);
			$this->delete(USER_GET_RELATION . $intTargetId);
			$this->delete(USER_GET_PARTNER . $intTargetId . '0');
			$this->delete(USER_GET_PARTNER . $intTargetId . '1');
		}
		
	}
	/* NEWS*/
	public function deleteNewsById($intNewsId) {
		$this->delete(NEWS_GET . $intNewsId);
		$this->delete(BACKEND_NEWS_GET . $intNewsId);
		$this->delete(NEWS_GETCMTTOTAL . $intNewsId);		
		$this->delete(NEWS_GETLIKE . $intNewsId);		
		$this->delete(NEWS_GETTOPCMT . $intNewsId);		
		$this->delete(NEWS_GETCMTUSER . $intNewsId);		
		$this->delete(NEWS_GETQUOTE . $intNewsId . '52');		
		$this->delete(NEWS_GETQUOTE . $intNewsId . '53');		
		$this->delete(NEWS_GETQUOTE . $intNewsId . '54');		
	}
	public function deleteNews($intSubCate, $intUserId=0) {		
		$this->delete(NEWS_GETRSS);
		$this->delete(NEWS_GETALLFORDASHBOARD . '0');
		$this->delete(NEWS_GETALLFORDASHBOARD . '1');
		$this->delete(NEWS_GETALL . $intSubCate . '00');
		$this->delete(NEWS_GETALL . $intSubCate . '01');
		$this->delete(NEWS_GETALL . $intSubCate . '02');
		$this->delete(NEWS_GETALL . $intSubCate . '03');
		$this->delete(NEWS_GETALL . $intSubCate . '04');
		$this->delete(NEWS_GETALL . $intSubCate . '05');
		$this->delete(NEWS_GETALL . $intSubCate . '06');
		$this->delete(NEWS_GETALL . $intSubCate . '10');
		$this->delete(NEWS_GETALL . $intSubCate . '11');
		$this->delete(NEWS_GETALL . $intSubCate . '12');
		$this->delete(NEWS_GETALL . $intSubCate . '13');
		$this->delete(NEWS_GETALL . $intSubCate . '14');
		$this->delete(NEWS_GETALL . $intSubCate . '15');
		$this->delete(NEWS_GETALL . $intSubCate . '16');
		$this->delete(NEWS_GETALL . $intSubCate . '20');
		$this->delete(NEWS_GETALL . $intSubCate . '21');
		$this->delete(NEWS_GETALL . $intSubCate . '22');
		$this->delete(NEWS_GETALL . $intSubCate . '23');
		$this->delete(NEWS_GETALL . $intSubCate . '24');
		$this->delete(NEWS_GETALL . $intSubCate . '25');
		$this->delete(NEWS_GETALL . $intSubCate . '26');
		$this->delete(NEWS_GETALL . $intSubCate . '30');
		$this->delete(NEWS_GETALL . $intSubCate . '31');
		$this->delete(NEWS_GETALL . $intSubCate . '32');
		$this->delete(NEWS_GETALL . $intSubCate . '33');
		$this->delete(NEWS_GETALL . $intSubCate . '34');
		$this->delete(NEWS_GETALL . $intSubCate . '35');
		$this->delete(NEWS_GETALL . $intSubCate . '36');	
		$this->delete(NEWS_GETALLBYUSER . $intUserId);	
		if($intUserId > 0) {
			$this->deleteUstat($intUserId);
		}
	}
	public function deleteFollowForNews($intUserId, $intNewsId) {
		$this->delete(NEWS_GETFOLLOW . $intUserId . $intNewsId);
		$this->delete(NEWS_GETFOLLOWBYNEWID . $intNewsId);
	}
	/** NOTIFICATION */
	public function deleteNotification($intUserId) {
		$this->delete(NOTIFICATION_GETNOTIFYBYUSERID . $intUserId);
		$this->delete(NOTIFICATION_GETNOTIFYUNREAD . $intUserId);
	}
	/** PHOTO */
	public function deleteAlbumByUserId($intUserId, $intAlbumId=0) {
		$this->delete(PHOTO_GETALBUMBYUSERID . $intUserId);
		$this->delete(PHOTO_GETALBUM . $intUserId . '0');
		$this->delete(PHOTO_GETALBUM . $intUserId . '1');
		$this->delete(PHOTO_GETALBUM . $intUserId . '2');
		if($intAlbumId > 0) {
			$this->delete(PHOTO_GETIMAGEBYALBUMID . $intUserId . $intAlbumId);
			$this->delete(PHOTO_GETALBUMINFO . $intAlbumId);
			$this->delete(PHOTO_GETPHOTOBYALBUM . $intAlbumId . '0');
			$this->delete(PHOTO_GETPHOTOBYALBUM . $intAlbumId . '1');
			$this->delete(PHOTO_GETPHOTOBYALBUM . $intAlbumId . '2');
			$this->delete(PHOTO_GETIMAGEFORALBUM . $intAlbumId);
		}
	}
	public function deleteCmtForPhoto($intImageId) {
		$this->delete(PHOTO_GETCMTTOTAL . $intImageId);
		$this->delete(PHOTO_GET . '0' . $intImageId);
		$this->delete(PHOTO_GETTOPCMT . $intImageId);
		$this->delete(PHOTO_GETCMTUSER . $intImageId);
		$this->delete(PHOTO_GETQUOTE . $intImageId . '22');
		$this->delete(PHOTO_GETQUOTE . $intImageId . '23');
		$this->delete(PHOTO_GETQUOTE . $intImageId . '24');
		$this->delete(PHOTO_GETLIKE . $intImageId);
	}
	/** FORTUNE */
	public function deleteFortuneByUser($intUserId, $intProductId=0) {
		$this->delete(PRODUCT_GETALLFORFORTUNE . $intUserId);
		$this->delete(PRODUCT_GETALLFORPROPOSE . $intUserId);
		$this->delete(PRODUCT_GETALLFORGIFT . $intUserId);
		if($intProductId > 0) {
			$this->delete(PRODUCT_GETALLFORPRODUCT . $intUserId);
		}
		$objVfriendUser	= new Vfriend_User();
		$intPartnerId 	= $objVfriendUser->getPartner($intUserId);
		if($intPartnerId > 0) {
			$this->delete(PRODUCT_GETALLFORFORTUNE . $intPartnerId);
			$this->delete(PRODUCT_GETALLFORPROPOSE . $intPartnerId);
		}
	}
	/** COVER */
	public function deleteCoverById($intCoverId) {
		$this->delete(BACKEND_COVER_GET . $intCoverId);
		$this->delete(COVER_GET . $intCoverId);
		$this->delete(COVER_GETALL . '-1');
	}
	public function deleteCoverByUserId($intUserId) {
		$this->delete(COVER_GETCOVERBYUSERID . $intUserId);
		$this->delete(COVER_GETALL . $intUserId);
	}
	/** FULL-HOUSE */
	public function deleteUblastById($intUblastId) {
		$this->delete(FULLHOUSE_GET . $intUblastId);
		$this->delete(FULLHOUSE_GETCMTUSER . $intUblastId);
		$this->delete(FULLHOUSE_GETCMTTOTAL . $intUblastId);
		$this->delete(FULLHOUSE_GETTOPCMT . $intUblastId);
		$this->delete(FULLHOUSE_GETLIKE . $intUblastId);
		$this->delete(FULLHOUSE_GETQUOTE . $intUblastId . '32');
		$this->delete(FULLHOUSE_GETQUOTE . $intUblastId . '34');
	}
	/** PLACES */
	public function deletePlaces($intSubCate, $intProvince=0) {
		$this->delete(PLACE_GETALL . $intSubCate . $intProvince . '0');
		$this->delete(PLACE_GETALL . $intSubCate . $intProvince . '1');
		$this->delete(PLACE_GETALL . $intSubCate . '00' );
		$this->delete(PLACE_GETALL . $intSubCate . '01' );
		$this->delete(PLACE_GETALL . '000');
		$this->delete(PLACE_GETALL . '001');
		$this->delete(PLACE_GETRSS);
	}
	
	public function deletePlaceById($intPlaceId) {
		$this->delete(PLACE_GET . $intPlaceId );
		$this->delete(PLACE_GETALLMEMBERLIKE . $intPlaceId );			
		$this->delete(PLACE_GETIMAGETOTAL . $intPlaceId );			
		$this->delete(PLACE_GETIMAGES . $intPlaceId . '0');			
		$this->delete(PLACE_GETIMAGES . $intPlaceId . '1');			
		$this->delete(PLACE_GETLIKE . $intPlaceId );			
		$this->delete(PLACE_GETTOPCMT . $intPlaceId );			
		$this->delete(PLACE_GETQUOTE . $intPlaceId . '62');			
		$this->delete(PLACE_GETQUOTE . $intPlaceId . '63');			
	}
	
	public function deletePlaceFavourite($intUserId) {
		$this->delete(PLACE_GETALLFAVOURITE . $intUserId);
	}
	
	public function deletePlaceForCmt($intPlaceId,$intUserId) {
		$this->delete(PLACE_GETCMT . $intPlaceId . $intUserId);
	}
	public function deletePlaceForImg($intPimageId) {
		$this->delete(PLACE_GETIMAGE . $intPimageId);
	}
	/** OFFLINE */
	public function deleteOfflineByUserId($intUserId) {
		$this->delete(OFFLINE_GETALLFORMATCH . $intUserId . OFFLINE_TOP_LIMIT);
		$this->delete(OFFLINE_GETALLFORMATCH . $intUserId . OFFLINE_LIMIT);
		$this->delete(OFFLINE_GETALL . $intUserId . OFFLINE_TOP_LIMIT);
		$this->delete(OFFLINE_GETALL . $intUserId . OFFLINE_LIMIT);
		$this->delete(OFFLINE_GETALLFORMINE . $intUserId . '0' . OFFLINE_TOP_LIMIT);
		$this->delete(OFFLINE_GETALLFORMINE . $intUserId . '0' . OFFLINE_LIMIT);
		$this->delete(OFFLINE_GETALLFORMINE . $intUserId . '1' . OFFLINE_LIMIT);
		$this->delete(OFFLINE_GETALLFORMINE . $intUserId . '2' . OFFLINE_LIMIT);
		$this->delete(OFFLINE_GETALLFOREXPIRE . $intUserId);
		$this->delete(OFFLINE_GETRSS);
	}
	public function deleteOfflineByCategory($intCategoryId) {
		$this->delete(OFFLINE_GETALLFORCATEGORY . $intCategoryId );
	}
	public function deleteOfflineById($intOfflineId, $intUserId=0) {
		$this->delete(OFFLINE_GET . $intOfflineId );
		$this->delete(OFFLINE_GETOJOIN . $intUserId . $intOfflineId );
		$this->delete(OFFLINE_LISTFRIENDINVITE . $intOfflineId);
		$this->delete(OFFLINE_GETALLFOROJOIN . $intOfflineId . '0');
		$this->delete(OFFLINE_GETALLFOROJOIN . $intOfflineId . '1');
		$this->delete(OFFLINE_GETALLFOROJOIN . $intOfflineId . '3');
		$this->delete(OFFLINE_GETALLFOROJOIN . $intOfflineId . '4');
		$this->delete(OFFLINE_GETALLFOREXPIRE . $intUserId);
	}
	public function deleteCmtByOfflineId($intOfflineId) {
		$this->delete(OFFLINE_GETTOPCMT . $intOfflineId);
		$this->delete(OFFLINE_GETCMTTOTAL . $intOfflineId);
		$this->delete(OFFLINE_GETCMTUSER . $intOfflineId);
	}
}
?>
